//package com.sjh.applicationannotation
//
//import com.google.auto.service.AutoService
//import javax.annotation.processing.*
//import javax.lang.model.SourceVersion
//import javax.lang.model.element.TypeElement
//import com.sun.org.apache.xerces.internal.util.DOMUtil.getAnnotation
//import java.io.IOException
//import javax.annotation.processing.RoundEnvironment
//import jdk.nashorn.internal.codegen.CompilerConstants.className
//import javax.tools.JavaFileObject
//
//
//
//
//
///**
// *
// * @author Extends
// * @date 2020/6/19
// */
//@AutoService(value = Processor::class)
//@SupportedAnnotationTypes(value = ["com.sjh.applicationannotation.Application"])
//@SupportedSourceVersion(SourceVersion.RELEASE_7)
//class ApplicationProcessor1 : AbstractProcessor() {
//    private var filer:Filer? = null
//    private val mData = arrayListOf<String>()
//
//    override fun init(p0: ProcessingEnvironment?) {
//        super.init(p0)
//        filer = processingEnv.filer
//    }
//
//    override fun process(p0: MutableSet<out TypeElement>?, p1: RoundEnvironment?): Boolean {
//        if(p1 == null) return false
//        collectInfo(p1)
//        writeToFile()
//        return true
//    }
//
//    //收集所有被注解的类的信息
//    private fun collectInfo(roundEnvironment: RoundEnvironment) {
//        val elements = roundEnvironment.getElementsAnnotatedWith(Application::class.java)
//        for (element in elements) {
//            val typeElement = element as TypeElement
//            val classFullName = typeElement.qualifiedName.toString()
//            mData.add(classFullName)
//        }
//    }
//
//    //将被注解的类的信息，写到一个类""Test$$AppLogic.java""中
//    fun writeToFile() {
//        try {
////            val packageFullName = "com.px.applogicdem"
//
//
//
////            val ArrayList = ClassName.get("java.util", "ArrayList")
////
////            val appLogicInfo = ClassName.get("com.px.api", "AppLogicInfo")
////            val arrayListType = ParameterizedTypeName.get(ArrayList, appLogicInfo)
////            val arrayList = FieldSpec.builder(arrayListType, "testArrayList")
////                .addModifiers(Modifier.PUBLIC)
////                .initializer("new \$T()", arrayListType)
////                .build()
////
////            val methodSpec2 = MethodSpec.constructorBuilder()
////                .addModifiers(Modifier.PUBLIC)
////            for (i in 0 until mData.size()) {
////                val temp = "temp$i"
////                methodSpec2.addStatement("\$T $temp = new \$T()", appLogicInfo, appLogicInfo)
////                    .addStatement("$temp.setClassName(\$S)", mData[i].getClassName())
////                    .addStatement(temp + ".setDelay(" + mData[i].isDelay() + ")")
////                    .addStatement(temp + ".setPriority(" + mData[i].getPriority() + ")")
////                    .addStatement("testArrayList.add($temp)")
////            }
////            // 构建Class
////            val typeSpec = TypeSpec.classBuilder("Test" + "$\$AppLogic")
////                .addModifiers(Modifier.PUBLIC)
////                .addMethod(methodSpec2.build())
////                .addField(arrayList)
////                .build()
////            val javaFile = JavaFile.builder(packageFullName, typeSpec)
////                .build()
//            // 生成class文件
////            javaFile.writeTo(filer)
//            if(filer == null) return
//            if(mData.isEmpty()) return
//            val className = mData[0]
//
//            val code = """
//                public class $className${'$'}${'$'}Application{
//                    public void init(ArrayList<String> list){
//                        list.add("$className");
//                    }
//                }
//            """.trimIndent()
//
//            val file = filer!!.createSourceFile("Test")
//            val writer = file.openWriter()
//            writer.write(code)
//            writer.close()
//
//        } catch (e: IOException) {
//            e.printStackTrace()
//        }
//
//    }
//}